package org.mili.ticketeer.service;

import org.mili.ticketeer.dao.DaoFactory;
import org.mili.ticketeer.dao.GroupDao;
import org.mili.ticketeer.dao.ModificationResult;
import org.mili.ticketeer.dto.Group;
import org.mili.ticketeer.util.Lambda;

import java.util.List;

public class GroupService extends Service {
	private GroupDao groupDao = DaoFactory.getDao(GroupDao.class);

    public ModificationResult write(final Group group) throws ServiceException {
        return doInService(new Lambda<ModificationResult>() {
            @Override
            public ModificationResult exec(Object... params) throws Exception {
                return groupDao.write(group);
            }
        });
    }

    public List<Group> getGroups() throws ServiceException {
        return doReadInService(new Lambda<List<Group>>() {
            @Override
            public List<Group> exec(Object... params) throws Exception {
                return groupDao.getGroups();
            }
        });
    }

    public Group findById(final int id) throws ServiceException {
        return doReadInService(new Lambda<Group>() {
            @Override
            public Group exec(Object... params) throws Exception {
                return groupDao.findById(id);
            }
        });
    }


}

